package _18_剑指OfferII;

public class _042_剑指OfferII最近请求次数 {

    private int[] ans;

    private int start;

    private int end;

    public _042_剑指OfferII最近请求次数() {
        ans = new int[3002];
    }

    // 使用环形数组记录
    public int ping(int t) {
        ans[end++] = t;
        end = end == ans.length? 0: end;
        while (ans[start] < t - 3000) {
            start++;
            start = start == ans.length? 0: start;
        }
        if (start > end) {
            return ans.length - (start - end);
        }

        return end - start;
    }


   /* private Queue<Integer> queue;

    public _042_剑指OfferII最近请求次数() {
        queue = new LinkedList<>();
    }

    public int ping(int t) {
        queue.add(t);

        while (queue.peek() < t - 3000) queue.poll();

        return queue.size();
    }*/
}
